//
//  vdTextfield.h
//  Void Dead
//
//  Created by Sidney Just on 13.03.10.
//
//  Copyright © 2009 by Sidney Just
//  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
//  documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
//  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
//  and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
//  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
//  PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
//  FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
//  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#import <Foundation/Foundation.h>

#import "vdNode.h"
#import "vdShape.h"
#import "vdLabel.h"
#import "vdKernel.h"

#import "vdTexManager.h"

/**
 * This class gives the user the possibility to edit a text at runtime.
 
 \todo: This class needs to be tested and extended!
 **/
@interface vdTextField : vdNode <vdGUIProtocol, UITextFieldDelegate> {
	//\cond
	BOOL isKeyboardVisible;
	
	vdShape *background;
	vdLabel *label;
	
	int offsetLeft;
	int offsetRight;
	
	unsigned int maxCharacters;
	
	UITextAlignment textAlignment;
	UIKeyboardType  keyboardType;
	
	BOOL hideOnLostFocus;
	BOOL hideOnReturn;
	
	NSString *text;
	
	id delegate;
	//\endcond
	
	@private
	UITextField *textfield;
}

/**
 * The maximum amount of characters that the text field can hold. If this variable is set to 0 (default) the text field isn't limited
 **/
@property unsigned int maxCharacters;

/**
 * The delegate of the text field. The delegate will be notified about changes (see the vdInterfaceProtocol)
 **/
@property (readwrite, assign) id delegate;

/**
 * Pointer to the current text (the pointer can change at runtime!)
 **/
@property (readonly) NSString *text;

/**
 * This variable can be used to determine if the keyboard is visible. If this is = YES the keyboard is visible and the user types into the text field, otherwise NO
 **/
@property (readonly) BOOL isKeyboardVisible;

/**
 * If this is set to YES (default) then the keyboard will be hidden if the user touches outside of the text field
 **/
@property BOOL hideOnLostFocus;

/**
 * If this is set to YES (default) then the keyboard will be hidden if the user presses the return button
 **/
@property BOOL hideOnReturn;

/**
 * The alignment of the text
 **/
@property UITextAlignment textAlignment;

/**
 * The keyboard type
 **/
@property UIKeyboardType  keyboardType;

/**
 * The left offset. The offset is the space between the beginning of the texture and the text (this will be used if the alignment is != UITextAlignmentRight)
 **/
@property int offsetLeft;

/**
 * The right offset. The offset is the space between the ending of the texture and the text (this will be used if the alignment is != UITextAlignmentLeft)
 **/
@property int offsetRight;

/**
 * This function can be used to hide the keyboard.
 @return YES if the keyboard is hidden, otherwise NO
 **/
- (BOOL)hideKeyboard;

/**
 * This function can be used to show the keyboard.
 @return YES if the keyboard is visible, otherwise NO
 **/
- (BOOL)showKeyboard;

/**
 * Sets the background texture. The background texture is visible under the text and must be set, otherwise the text field might behave wrong!
 @param _tex Filename of the texture
 **/
- (void)setTexture:(NSString *)_tex;

/**
 * Sets a new text for the text field
 @param string The new text
 @remark The length of the string must be smaller or equal than maxCharacters! (However, this doesn't count if maxCharacters is set to 0)
 **/
- (void)setText:(NSString *)string;

/**
 * Creates a new text field with the given texture
 @param _tex Filename of the texture
 @return Pointer to the new instance
 **/
- (id)initWithTexture:(NSString *)_tex;

@end
